﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BootstrapMvcSample.Controllers;
using FuturM.PourL.DAL;

namespace FuturM.PourL.UI.WEB.Controllers
{
    public class PersonController : Controller
    {
        private PourEllesBDEntities db = new PourEllesBDEntities();

        //
        // GET: /Person/

        public ActionResult Index()
        {
            return View(db.PersonneSets.ToList());
        }

        //
        // GET: /Person/Details/5

        public ActionResult Details(int id = 0)
        {
            PersonneSet personneset = db.PersonneSets.Find(id);
            if (personneset == null)
            {
                return HttpNotFound();
            }
            return View(personneset);
        }

        //
        // GET: /Person/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Person/Create

        [HttpPost]
        public ActionResult Create(PersonneSet personneset)
        {
            if (ModelState.IsValid)
            {
                db.PersonneSets.Add(personneset);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
        
            return View(personneset);
        }

        //
        // GET: /Person/Edit/5

        public ActionResult Edit(int id = 0)
        {
            PersonneSet personneset = db.PersonneSets.Find(id);
            if (personneset == null)
            {
                return HttpNotFound();
            }
            return View(personneset);
        }

        //
        // POST: /Person/Edit/5

        [HttpPost]
        public ActionResult Edit(PersonneSet personneset)
        {
            if (ModelState.IsValid)
            {
                db.Entry(personneset).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(personneset);
        }

        //
        // GET: /Person/Delete/5

        public ActionResult Delete(int id = 0)
        {
            PersonneSet personneset = db.PersonneSets.Find(id);
            if (personneset == null)
            {
                return HttpNotFound();
            }
            return View(personneset);
        }

        //
        // POST: /Person/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            PersonneSet personneset = db.PersonneSets.Find(id);
            db.PersonneSets.Remove(personneset);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }

        public ActionResult Downloads()
        {
            var dir = new System.IO.DirectoryInfo(Server.MapPath("~/App_Data/Carnet/"));
            System.IO.FileInfo[] fileNames = dir.GetFiles("*.*");
            List<string> items = new List<string>();
            foreach (var file in fileNames)
            {

                items.Add(file.Name);
            }
            return View(items);
        }

        public ActionResult AddMedicalForFemmeEnceinte(int id)
        {
            PersonneSet personneset = db.PersonneSets.Find(id);
            if (personneset.Nom == "Admin")
            {
                RedirectToAction("Index");
            }
            return View();


        }


        public ActionResult Calendrier()
        {
            return View();
        }


    }
}